package com.java.utils;

import com.java.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

//通过前端请求 获取请求头里的token 返回userId 和 userName
public class AuthContextHolder {

    //根据请求获取header里面的token 通过jwt工具类获取里面的userid
    public static Long getUserId(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    //获取用户名
    public static String getUsername(HttpServletRequest request){
        String token = request.getHeader("token");
        String username = JwtHelper.getUserName(token);
        return username;
    }
}
